package cc.toprank.syncdatatask.pojo;

import com.toprank.druid.store.jdbc.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/** 
 * description 获取商家档案ID
 * User: WeiDa
 * Date: 2017-4-1
 * Time: 13:45
 */
public class RshHandler {

    public static final ResultSetHandler<List<Merchant>> Merchant_LIST_RSH = new ResultSetHandler<List<Merchant>>() {
        @Override
        public List<Merchant> handle(ResultSet rs) throws SQLException {
            List<Merchant> Merchants = new ArrayList<>();

            while (rs.next()) {
                Merchants.add(getMerchantByRs(rs));
            }
            return Merchants;
        }
    };

    public static final ResultSetHandler<Merchant> Merchant_RSH = new ResultSetHandler<Merchant>() {
        @Override
        public Merchant handle(ResultSet rs) throws SQLException {
            if (rs.next()) {
                return getMerchantByRs(rs);
            }
            return null;
        }
    };

    private static Merchant getMerchantByRs(final ResultSet rs) throws SQLException {
        Merchant merchant = new Merchant();
        merchant.setArchiveID(rs.getLong("ArchiveID"));
        merchant.setOrgID(rs.getLong("OrgID"));
        return merchant;
    }





    public static final ResultSetHandler<List<Organization>> Organization_LIST_RSH = new ResultSetHandler<List<Organization>>() {
        @Override
        public List<Organization> handle(ResultSet rs) throws SQLException {
            List<Organization> Organizations = new ArrayList<>();

            while (rs.next()) {
                Organizations.add(getOrganizationByRs(rs));
            }
            return Organizations;
        }
    };

    public static final ResultSetHandler<Organization> Organization_RSH = new ResultSetHandler<Organization>() {
        @Override
        public Organization handle(ResultSet rs) throws SQLException {
            if (rs.next()) {
                return getOrganizationByRs(rs);
            }
            return null;
        }
    };

    private static Organization getOrganizationByRs(final ResultSet rs) throws SQLException {
        Organization organization = new Organization();
        organization.setParentID(rs.getLong("ParentID"));
        organization.setOrgID(rs.getLong("OrgID"));
        return organization;
    }

   
}
